<?php
$no_array=array('/mobile/register.php');
if(strpos( $_SERVER['HTTP_USER_AGENT'],'MicroMessenger') > 0 && !in_array($_SERVER['PHP_SELF'],$no_array))
{
    if(!in_array($_SERVER['PHP_SELF'],$no_array))
    {
        require(ROOT_PATH . 'includes/oauth2.php');

        if (empty($_SESSION['openids'])) 
        {
            $uri = 'http://ytt2.tophp.cn/mobile/';
            path_weixin($uri);
            die();
        }
        file_put_contents('233.txt', 'oppenid is :'.$_SESSION['openids']);
        $wx_user=$db->getRow("SELECT * FROM wx_weixin_user WHERE wxid = '{$_SESSION['openids']}'");
        $user_info = $db->getRow("SELECT * FROM wx_users WHERE wecha_id = '{$_SESSION['openids']}'");
        //关注但是没有登录过要创建账号
        if (empty($user_info)) 
        { 
            $subscribe = $_SESSION['wei_info']->subscribe;
            $openid = $_SESSION['wei_info']->openid;
            $nickname = $_SESSION['wei_info']->nickname;
            $sex = $_SESSION['wei_info']->sex;
            $language = $_SESSION['wei_info']->language;
            $city = $_SESSION['wei_info']->city;
            $province = $_SESSION['wei_info']->province;
            $country = $_SESSION['wei_info']->country;
            $headimgurl = $_SESSION['wei_info']->headimgurl;
            $rec_id = $wx_user['rec_id'];

            $GLOBALS['db']->query(' INSERT INTO '.$GLOBALS['ecs']->table('users').' ( user_name, wecha_id, head_img, parent_id ) VALUES ( "'.$nickname.'", "'.$openid.'", "'.$headimgurl.'","'.$rec_id.'" ) ');
        }
    }
}
?>

